package com.pxene.hbasecount;

import java.io.IOException;

import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;

public class HBaseCountMapper extends TableMapper<Text,LongWritable> {

	private Text resultKey = new Text();
	private LongWritable resultVal = new LongWritable(1);

	@Override
	protected void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException {
		String rowkey = Bytes.toString(value.getRow());
		String code=rowkey.substring(0, 4);
		resultKey.set(code);
		context.write(resultKey, resultVal);
	}

}